const { DataTypes } = require('sequelize');
const seq = require('../db/seq');
const BorrowRecord=require('./BorrowRecord.model')
const Bookser = seq.define('bookser', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false
    },
    is_borrowed: {
        type: DataTypes.STRING(255),
        allowNull: true,
        comment: '是否借出'
    },
    is_deleted:{
        type: DataTypes.STRING(255),
        allowNull: true,
        comment: '是否删除'
    },
    title: {
        type: DataTypes.STRING(255),
        allowNull: true,
        comment: '书籍名称'
    },
    author: {
        type: DataTypes.STRING(100),
        allowNull: true,
        comment: '著/编/译者'
    },
    publisher: {
        type: DataTypes.STRING(100),
        allowNull: true,
        comment: '出版社'
    },
    publish_year: {
        type: DataTypes.STRING(100),
        allowNull: true,
        comment: '出版时间'
    },
    source: {
        type: DataTypes.STRING(100),
        allowNull: true,
        comment: '来源'
    },
    category: {
        type: DataTypes.STRING(50),
        allowNull: true,
        comment: '类型'
    },
    created_at: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: DataTypes.NOW,
        field: 'created_at'
    },
    updated_at: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: DataTypes.NOW,
        field: 'updated_at',
        onUpdate: DataTypes.NOW
    }
}, {
    tableName: 'bookser',
    timestamps: false,
});
// Bookser.hasMany(BorrowRecord, { foreignKey: 'book_id' });
// BorrowRecord.belongsTo(Bookser, { foreignKey: 'book_id' });
module.exports = Bookser;
